<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备名称" prop="pointName">
        <el-input
          v-model="queryParams.pointName"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="园区编码" prop="pointPart">
        <el-input
          v-model="queryParams.pointPart"
          placeholder="请输入园区编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="楼号编码" prop="pointBuilding">
        <el-input
          v-model="queryParams.pointBuilding"
          placeholder="请输入楼号编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="层数" prop="pointFloat">
        <el-input
          v-model="queryParams.pointFloat"
          placeholder="请输入层数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机房" prop="pointRoom">
        <el-input
          v-model="queryParams.pointRoom"
          placeholder="请输入机房"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属巡检范围" prop="pointScope">
        <el-input
          v-model="queryParams.pointScope"
          placeholder="请输入所属巡检范围"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="巡检类别" prop="pointType">
        <el-select v-model="queryParams.pointType" placeholder="请选择巡检类别" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="日常巡逻要求" prop="pointDemand">
        <el-input
          v-model="queryParams.pointDemand"
          placeholder="请输入日常巡逻要求"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="判定标准" prop="pointStandard">
        <el-input
          v-model="queryParams.pointStandard"
          placeholder="请输入判定标准"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="周期" prop="pointTimes">
        <el-input
          v-model="queryParams.pointTimes"
          placeholder="请输入周期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="巡检方法" prop="pointWay">
        <el-input
          v-model="queryParams.pointWay"
          placeholder="请输入巡检方法"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检查目的" prop="pointAim">
        <el-input
          v-model="queryParams.pointAim"
          placeholder="请输入检查目的"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="后续处置方法" prop="pointHandle">
        <el-input
          v-model="queryParams.pointHandle"
          placeholder="请输入后续处置方法"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考核指标" prop="pointTarget">
        <el-input
          v-model="queryParams.pointTarget"
          placeholder="请输入考核指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="示例" prop="pointDemo">
        <el-input
          v-model="queryParams.pointDemo"
          placeholder="请输入示例"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['md:point:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['md:point:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['md:point:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['md:point:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="pointList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="设备名称" align="center" prop="pointName" />
      <el-table-column label="园区编码" align="center" prop="pointPart">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.new_business_park" :value="scope.row.pointPart"/>
        </template>
      </el-table-column>
      <el-table-column label="楼号编码" align="center" prop="pointBuilding">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.new_building" :value="scope.row.pointBuilding"/>
        </template>
      </el-table-column>
      <el-table-column label="层数" align="center" prop="pointFloat" />
      <el-table-column label="机房" align="center" prop="pointRoom">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.new_machine_room" :value="scope.row.pointRoom"/>
        </template>
      </el-table-column>
      <el-table-column label="所属巡检范围" align="center" prop="pointScope">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.inspection_scope" :value="scope.row.pointScope"/>
        </template>
      </el-table-column>
      <el-table-column label="巡检类别" align="center" prop="pointType" />
      <el-table-column label="日常巡逻要求" align="center" prop="pointDemand" />
      <el-table-column label="判定标准" align="center" prop="pointStandard" />
      <el-table-column label="周期" align="center" prop="pointTimes">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.new_inspection_times" :value="scope.row.pointTimes"/>
        </template>
      </el-table-column>
      <el-table-column label="巡检方法" align="center" prop="pointWay" />
      <el-table-column label="检查目的" align="center" prop="pointAim" />
      <el-table-column label="后续处置方法" align="center" prop="pointHandle" />
      <el-table-column label="考核指标" align="center" prop="pointTarget" />
      <el-table-column label="示例" align="center" prop="pointDemo" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['md:point:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['md:point:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改巡检点对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="设备名称" prop="pointName">
          <el-input v-model="form.pointName" placeholder="请输入设备名称" />
        </el-form-item>
        <el-form-item label="园区编码" prop="pointPart">
          <el-input v-model="form.pointPart" placeholder="请输入园区编码" />
        </el-form-item>
        <el-form-item label="楼号编码" prop="pointBuilding">
          <el-input v-model="form.pointBuilding" placeholder="请输入楼号编码" />
        </el-form-item>
        <el-form-item label="层数" prop="pointFloat">
          <el-input v-model="form.pointFloat" placeholder="请输入层数" />
        </el-form-item>
        <el-form-item label="机房" prop="pointRoom">
          <el-input v-model="form.pointRoom" placeholder="请输入机房" />
        </el-form-item>
        <el-form-item label="所属巡检范围" prop="pointScope">
          <el-input v-model="form.pointScope" placeholder="请输入所属巡检范围" />
        </el-form-item>
        <el-form-item label="巡检类别" prop="pointType">
          <el-select v-model="form.pointType" placeholder="请选择巡检类别">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="日常巡逻要求" prop="pointDemand">
          <el-input v-model="form.pointDemand" placeholder="请输入日常巡逻要求" />
        </el-form-item>
        <el-form-item label="判定标准" prop="pointStandard">
          <el-input v-model="form.pointStandard" placeholder="请输入判定标准" />
        </el-form-item>
        <el-form-item label="周期" prop="pointTimes">
          <el-input v-model="form.pointTimes" placeholder="请输入周期" />
        </el-form-item>
        <el-form-item label="巡检方法" prop="pointWay">
          <el-input v-model="form.pointWay" placeholder="请输入巡检方法" />
        </el-form-item>
        <el-form-item label="检查目的" prop="pointAim">
          <el-input v-model="form.pointAim" placeholder="请输入检查目的" />
        </el-form-item>
        <el-form-item label="后续处置方法" prop="pointHandle">
          <el-input v-model="form.pointHandle" placeholder="请输入后续处置方法" />
        </el-form-item>
        <el-form-item label="考核指标" prop="pointTarget">
          <el-input v-model="form.pointTarget" placeholder="请输入考核指标" />
        </el-form-item>
        <el-form-item label="示例" prop="pointDemo">
          <el-input v-model="form.pointDemo" placeholder="请输入示例" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPoint, getPoint, delPoint, addPoint, updatePoint } from "@/api/md/point";

export default {
  name: "Point",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 巡检点表格数据
      pointList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pointName: null,        pointPart: null,        pointBuilding: null,        pointFloat: null,        pointRoom: null,        pointScope: null,        pointType: null,        pointDemand: null,        pointStandard: null,        pointTimes: null,        pointWay: null,        pointAim: null,        pointHandle: null,        pointTarget: null,        pointDemo: null,      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询巡检点列表 */
    getList() {
      this.loading = true;
      listPoint(this.queryParams).then(response => {
        this.pointList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pointId: null,        pointName: null,        pointPart: null,        pointBuilding: null,        pointFloat: null,        pointRoom: null,        pointScope: null,        pointType: null,        pointDemand: null,        pointStandard: null,        pointTimes: null,        pointWay: null,        pointAim: null,        pointHandle: null,        pointTarget: null,        pointDemo: null,        pointUser: null,        pointCreateTime: null,        pointTemp: null      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pointId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加巡检点";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const pointId = row.pointId || this.ids
      getPoint(pointId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改巡检点";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.pointId != null) {
            updatePoint(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPoint(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pointIds = row.pointId || this.ids;
      this.$modal.confirm('是否确认删除巡检点编号为"' + pointIds + '"的数据项？').then(function() {
        return delPoint(pointIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('md/point/export', {
        ...this.queryParams
      }, `point_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
